package com.yq.day29;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/29 11:11
 */
public class Demo05 {
    public static final Object OBJECT = new Object();
    public static void main(String[] args) {

        new Thread(() -> {
            synchronized (OBJECT) {
                for (int i = 1; i < 100; i += 2) {
                    //唤醒
                    OBJECT.notify();
                    System.out.println(Thread.currentThread().getName() + "====" + i);
                    //阻塞
                    try {
                        OBJECT.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                OBJECT.notify();
            }
        }, "t1").start();



        new Thread(() -> {
            synchronized (OBJECT){
                for (int i = 2; i < 100; i+=2) {
                    //唤醒
                    OBJECT.notify();
                    System.out.println(Thread.currentThread().getName() + "====" + i);
                    try {
                        OBJECT.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                OBJECT.notify();
            }

        }, "t2").start();


    }
}
